// Copyright Epic Games, Inc. All Rights Reserved.

#include "Teams/LyraTeamAgentInterface.h"

#include "LyraLogChannels.h"
#include "UObject/ScriptInterface.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraTeamAgentInterface)

/**
 * 构造函数
 */
ULyraTeamAgentInterface::ULyraTeamAgentInterface(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

/**
 * 条件性地广播团队变化
 */
void ILyraTeamAgentInterface::ConditionalBroadcastTeamChanged(TScriptInterface<ILyraTeamAgentInterface> This, FGenericTeamId OldTeamID, FGenericTeamId NewTeamID)
{
	if (OldTeamID != NewTeamID) // 如果团队ID发生变化
	{
		const int32 OldTeamIndex = GenericTeamIdToInteger(OldTeamID);  // 转换旧团队ID为整数
		const int32 NewTeamIndex = GenericTeamIdToInteger(NewTeamID); // 转换新团队ID为整数

		UObject* ThisObj = This.GetObject(); // 获取对象
		UE_LOG(LogLyraTeams, Verbose, TEXT("[%s] %s assigned team %d"), *GetClientServerContextString(ThisObj), *GetPathNameSafe(ThisObj), NewTeamIndex); // 记录团队分配日志

		This.GetInterface()->GetTeamChangedDelegateChecked().Broadcast(ThisObj, OldTeamIndex, NewTeamIndex); // 广播团队变化
	}
}